//
//  FindPeopleWithConditionViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/4/1.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "FindPeopleWithConditionViewController.h"
#import "ShuRuLianxirenTableViewCell.h"
#import "SelectConditonTableViewCell.h"
#import "ZGWBiaoQianListViewController.h"
#import "ZGWSelectProviceCityDiQuViewController.h"
#import "ZGWBiaoQianModel.h"
#import "ZGWSearchFriendModel.h"
#import "ZGWFindPeopleWithConditionResultViewController.h"

#define kCurrentUserToken [[NSUserDefaults standardUserDefaults]objectForKey:@"token"]

@interface FindPeopleWithConditionViewController ()<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UIPickerViewDataSource, UIPickerViewDelegate>

@property (nonatomic, strong) UITableView *findPeopleWithConditionTableView; // tableview
@property (nonatomic, strong) UIButton *findButton; // 查找
@property (nonatomic, strong) UIPickerView *myPickerView; // 选项框
@property (nonatomic, strong) NSMutableArray *pickviewDataArray; // pickerview数组

@property (nonatomic, strong) NSMutableArray *genderArray; // 性别数组
@property (nonatomic, strong) NSMutableDictionary *genderDuiYingDic; // 性别对应的字典
@property (nonatomic, strong) NSMutableArray *ageArray; // 年龄数组
@property (nonatomic, strong) NSMutableDictionary *ageDuiYingDic; // 年龄对应的字典
@property (nonatomic, strong) NSMutableArray *geneSimularityArray; // 基因相似度数组
@property (nonatomic, strong) NSMutableArray *biaoQianArray; // 标签数组，里面存放ZGWBiaoQianModel

@property (nonatomic, strong) UIView *bottomView; // 底部view
@property (nonatomic, strong) NSString *foreverString;

@property (nonatomic, strong) NSMutableDictionary *userMessageDic; // 用户信息字典
@property (nonatomic, strong) UIView *noConditionView; // 没有条件的提示框

@property (nonatomic, strong) NSString *nikeNameString; // 昵称
@property (nonatomic, strong) NSString *genderString; // 性别
@property (nonatomic, strong) NSString *ageString; // 年龄
@property (nonatomic, strong) NSString *provinceString; // 省
@property (nonatomic, strong) NSString *cityString; // 市
@property (nonatomic, strong) NSMutableString *biaoQianString; // 标签
@property (nonatomic, strong) NSString *geneSimularityString; // 基因相似度

@property (nonatomic, strong) NSMutableArray *findWithConditionResultArray; // 根据条件查找的结果数组

@end

@implementation FindPeopleWithConditionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // navi的修改
    [self changeNavigation];
    // 数据源
    [self addData];
    // 添加tableview
    [self addTableview];
    // 添加查找button
    [self addFindButton];
    // 添加pickview
    [self addPickerView];
    // 添加无符合条件结果的提示框
    [self addNoAlert];
    
}

#pragma mark - 数据源
- (void)addData
{


    self.userMessageDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", @"name", @"不限", @"gender", @"不限",@"age", @"不限", @"address", @"不限", @"label", @"不限", @"xiangsidu" ,nil];
    // 性别
    self.genderArray = [NSMutableArray arrayWithObjects:@"不限", @"男", @"女", nil];
    // 性别对应的字典
    self.genderDuiYingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", @"不限", @"0", @"男", @"1", @"女", nil];
    // 年龄
    self.ageArray = [NSMutableArray arrayWithObjects:@"不限", @"18岁以下", @"18-22岁", @"23-26岁", @"27-35岁", @"35岁以上", nil];
    // 年龄对应的字典
    self.ageDuiYingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", @"不限", @"0-17", @"18岁以下", @"18-22", @"18-22岁", @"23-26", @"23-26岁", @"27-35", @"27-35岁", @"36-99", @"35岁以上", nil];
    // 基因相似度
    self.geneSimularityArray = [NSMutableArray arrayWithObjects:@"不限", @"90%~100%", @"80%~90%", @"70%~80%", @"60%~70%", @"50%~60%", @"40%~50%", @"30%~40%", @"20%~30%", @"10%~20%", @"10%以下", nil];
    // 标签数组
    self.biaoQianArray = [NSMutableArray array];
    // 赋初值
    [self changeFindButtonShouldZiFuChuan];
    
}

#pragma mark - 查找按钮需要的字符串要一直变化
- (void)changeFindButtonShouldZiFuChuan
{
    // 昵称
    self.nikeNameString = [self.userMessageDic valueForKey:@"name"];
    // 性别
    self.genderString = [self.genderDuiYingDic valueForKey:[self.userMessageDic valueForKey:@"gender"]];
    // 年龄
    self.ageString = [self.ageDuiYingDic valueForKey:[self.userMessageDic valueForKey:@"age"]];
    // 地区字符串
    if ([[self.userMessageDic valueForKey:@"address"] isEqualToString:@"不限"]) {
        self.provinceString = @"";
        self.cityString = @"";
    } else {
        NSArray *diQuArray = [[self.userMessageDic valueForKey:@"address"] componentsSeparatedByString:@"-"];
        // 省
        self.provinceString = diQuArray[0];
        // 市
        self.cityString = diQuArray[1];
    }
    
    // 标签
    if ([[self.userMessageDic valueForKey:@"label"] isEqualToString:@"不限"]) {
        self.biaoQianString = [NSMutableString stringWithFormat:@""];
    } else {
        for (int i = 0; i < self.biaoQianArray.count; i++) {
            ZGWBiaoQianModel *model = self.biaoQianArray[i];
            NSString *tempBiaoQianID = model.biaoQianID;
            NSString *resultBiaoQian = @"";
            if (i == 0) {
                resultBiaoQian = tempBiaoQianID;
            } else {
                resultBiaoQian = [NSString stringWithFormat:@",%@", tempBiaoQianID];
            }
            [self.biaoQianString appendString:resultBiaoQian];
        }
    }
  
    
    // 基因相似度
    self.geneSimularityString = [self.userMessageDic valueForKey:@"xiangsidu"];
    
    
//    NSLog(@"昵称：%@，性别：%@，年龄：%@，基因相似度：%@", self.nikeNameString, self.genderString, self.ageString, self.geneSimularityString);
    NSLog(@"昵称：%@，性别：%@，年龄：%@，省：%@，市：%@，标签：%@，基因相似度：%@", self.nikeNameString, self.genderString, self.ageString, self.provinceString, self.cityString, self.biaoQianString, self.geneSimularityString);
}

// 添加无符合条件结果的提示框
- (void)addNoAlert
{
    self.noConditionView = [[UIView alloc] initWithFrame:CGRectMake((kScreenWidth - 350 * kAdjustParamater) / 2, 10 * kAdjustParamater, 350 * kAdjustParamater, 45 * kAdjustParamater)];
    self.noConditionView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    [self.view addSubview:_noConditionView];
    self.noConditionView.hidden = YES;
    
    UIImageView *noConditonImageV = [[UIImageView alloc] initWithFrame:CGRectMake(90 * kAdjustParamater, 12 * kAdjustParamater, 20 * kAdjustParamater, 20 * kAdjustParamater)];
    noConditonImageV.image = [UIImage imageNamed:@"noContidion-teshusousuo"];
    [self.noConditionView addSubview:noConditonImageV];
    UILabel *noConditonLabel = [[UILabel alloc] initWithFrame:CGRectMake(noConditonImageV.right + 2 * kAdjustParamater, 13 * kAdjustParamater, 150 * kAdjustParamater, 18 * kAdjustParamater)];
 //   noConditonLabel.backgroundColor = [UIColor redColor];
    noConditonLabel.text = @"无符合条件的结果";
    noConditonLabel.textColor = [UIColor whiteColor];
    noConditonLabel.font = [UIFont systemFontOfSize:17 * kAdjustParamater];
    [self.noConditionView addSubview:noConditonLabel];
    
}

// navi的修改
- (void)changeNavigation
{
    [self.navigationController.navigationBar setTranslucent:NO];
    self.navigationItem.title = @"按条件查找陌生人";
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    
}

#pragma mark - 返回上一页面
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 添加查找按钮
- (void)addFindButton
{
    self.findButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.findButton.frame = CGRectMake((kScreenWidth - 270 * kAdjustParamater) / 2, self.findPeopleWithConditionTableView.bottom + 45 * kAdjustParamater, 270 * kAdjustParamater, 40 * kAdjustParamater);
    self.findButton.backgroundColor = [UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1];
    [self.findButton setTitle:@"查 找" forState:UIControlStateNormal];
    [self.findButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.findButton.titleLabel.font = [UIFont systemFontOfSize:18 * kAdjustParamater];
    self.findButton.layer.cornerRadius = 5 * kAdjustParamater;
    [self.findButton addTarget:self action:@selector(findWithConditon:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_findButton];
}

#pragma mark - 查找按钮回调
- (void)findWithConditon:(UIButton *)button
{
    
     NSLog(@"昵称：%@，性别：%@，年龄：%@，省：%@，市：%@，标签：%@，基因相似度：%@", self.nikeNameString, self.genderString, self.ageString, self.provinceString, self.cityString, self.biaoQianString, self.geneSimularityString);
    [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] startAnimation];
    // 按条件查找的url
    NSString *findWithConditionUrl = [NSString stringWithFormat:@"%@?token=%@", kZGWFindFriendWithCondition, kCurrentUserToken];
    NSDictionary *paramaterDic = @{@"nikename":self.nikeNameString, @"sex":self.genderString, @"province":self.provinceString, @"city":self.cityString, @"industry":@"", @"age":self.ageString, @"tags_id":self.biaoQianString};
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:findWithConditionUrl parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
        if (!responseObject) {
            return;
        }
        // 搜索结果
        NSArray *persionsArray = [responseObject valueForKey:@"persions"];
        // 结果数组
        self.findWithConditionResultArray = [NSMutableArray array];
        if (persionsArray.count == 0) {
            self.noConditionView.hidden = NO;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                self.noConditionView.hidden = YES;
            });
            
        } else {
            for (NSDictionary *personDic in persionsArray) {
                ZGWSearchFriendModel *model = [[ZGWSearchFriendModel alloc] init];
                [model setValuesForKeysWithDictionary:personDic];
                [self.findWithConditionResultArray addObject:model];
            }
            ZGWFindPeopleWithConditionResultViewController *resultVC = [[ZGWFindPeopleWithConditionResultViewController alloc] init];
            resultVC.findWithConditonResultArray = [NSMutableArray arrayWithArray:self.findWithConditionResultArray];
            [self.navigationController pushViewController:resultVC animated:YES];
        }
       
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"数据获取失败，请重试" ToView:self];
    }];
}

#pragma mark - 添加tableview
- (void)addTableview
{
    self.findPeopleWithConditionTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 300 * kAdjustParamater) style:UITableViewStylePlain];
    self.findPeopleWithConditionTableView.bounces = NO;
    self.findPeopleWithConditionTableView.scrollEnabled = NO;
    self.findPeopleWithConditionTableView.showsVerticalScrollIndicator = NO;
    self.findPeopleWithConditionTableView.dataSource = self;
    self.findPeopleWithConditionTableView.delegate = self;
    [self.view addSubview:_findPeopleWithConditionTableView];
}

#pragma mark - tableView代理
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    } else {
        return 5;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        static NSString *identifier = @"linkPeople";
        ShuRuLianxirenTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[ShuRuLianxirenTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.addPeopleTF.delegate = self;
        return cell;
    }
    static NSString *identifier = @"selectCondition";
    SelectConditonTableViewCell *selectCell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (selectCell == nil) {
        selectCell = [[SelectConditonTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        selectCell.leftLabel.text = @"性    别";
         selectCell.rightLabel.text = [self.userMessageDic valueForKey:@"gender"];
    } else if (indexPath.section == 1 && indexPath.row == 1) {
        selectCell.leftLabel.text = @"年    龄";
        selectCell.rightLabel.text = [self.userMessageDic valueForKey:@"age"];
    } else if (indexPath.section == 1 && indexPath.row == 2) {
        selectCell.leftLabel.text = @"所在地";
        selectCell.rightLabel.text = [self.userMessageDic valueForKey:@"address"];
    } else if (indexPath.section == 1 && indexPath.row == 3) {
        selectCell.leftLabel.text = @"标    签";
        selectCell.rightLabel.text = [self.userMessageDic valueForKey:@"label"];
    } else if (indexPath.section == 1 && indexPath.row == 4) {
        selectCell.leftLabel.text = @"基因相似度";
        selectCell.rightLabel.text = [self.userMessageDic valueForKey:@"xiangsidu"];
    }
    selectCell.selectionStyle = UITableViewCellSelectionStyleNone;
    return selectCell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40 * kAdjustParamater;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
 
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10 *kAdjustParamater)];
        view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.03];
        return view;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
  
    return 20 * kAdjustParamater;
}
// 点击tableviewcell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"section = %ld, row = %ld", indexPath.section, indexPath.row);
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (indexPath.section == 1 && indexPath.row == 0) {
        // 说明点击性别
        self.pickviewDataArray = [NSMutableArray arrayWithArray:self.genderArray];
        self.bottomView.hidden = NO;
        self.foreverString = @"";
        [self.myPickerView selectRow:0 inComponent:0 animated:NO];
        [self.myPickerView reloadAllComponents];
    } else if (indexPath.section == 1 && indexPath.row == 1) {
        // 说明点击年龄
        self.pickviewDataArray = [NSMutableArray arrayWithArray:self.ageArray];
        self.bottomView.hidden = NO;
        [self.myPickerView selectRow:0 inComponent:0 animated:NO];
        // 初始化string
        self.foreverString = @"";
        [self.myPickerView reloadAllComponents];
    } else if (indexPath.section == 1 && indexPath.row == 2) {
        // 说明点击所在地
        ZGWSelectProviceCityDiQuViewController *zgwSelectProviceCityDiQuVC = [[ZGWSelectProviceCityDiQuViewController alloc] init];
        __block FindPeopleWithConditionViewController *mySelf = self;
        zgwSelectProviceCityDiQuVC.selectDiQu = ^void (NSString *diqu) {
            [mySelf.userMessageDic setValue:diqu forKey:@"address"];
            // 刷新界面
            [self.findPeopleWithConditionTableView reloadData];
            [self changeFindButtonShouldZiFuChuan];
        };
        [self.navigationController pushViewController:zgwSelectProviceCityDiQuVC animated:YES];
    } else if (indexPath.section == 1 && indexPath.row == 3) {
        // 说明点击标签
        ZGWBiaoQianListViewController *zgwBiaoQianListVC = [[ZGWBiaoQianListViewController alloc] init];
        __block FindPeopleWithConditionViewController *mySelf = self;
        zgwBiaoQianListVC.returnBiaoQianArray = ^void (NSMutableArray *biaoQianArray) {
            NSLog(@"标签数组回调");
            self.biaoQianArray = [NSMutableArray arrayWithArray:biaoQianArray];
            // 进行标签的组装
            NSMutableString *biaoQianString = [NSMutableString stringWithFormat:@""];
            for (int i = 0; i < biaoQianArray.count; i++) {
                ZGWBiaoQianModel *model = biaoQianArray[i];
                NSString *tempString = model.name;
                NSString *resultString = @"";
                if (i == 0) {
                    resultString = tempString;
                } else {
                    resultString = [NSString stringWithFormat:@"#%@", tempString];
                }
                [biaoQianString appendString:resultString];
            }
            [mySelf.userMessageDic setValue:biaoQianString forKey:@"label"];
            // 刷新界面
            [self.findPeopleWithConditionTableView reloadData];
            [self changeFindButtonShouldZiFuChuan];
        };
        [self.navigationController pushViewController:zgwBiaoQianListVC animated:YES];
    } else if (indexPath.section == 1 && indexPath.row == 4) {
        // 说明是点击基因相似度
        self.pickviewDataArray = [NSMutableArray arrayWithArray:self.geneSimularityArray];
        self.bottomView.hidden = NO;
        [self.myPickerView selectRow:0 inComponent:0 animated:NO];
        // 初始化string
        self.foreverString = @"";
        [self.myPickerView reloadAllComponents];
    }
    
}



#pragma mark - UITextField代理

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.userMessageDic setValue:textField.text forKey:@"name"];
    [self changeFindButtonShouldZiFuChuan];
    [textField resignFirstResponder];
    return YES;
}

#pragma mark - 添加pickerView
- (void)addPickerView
{
    self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.findButton.bottom, kScreenWidth, 200)];
    self.bottomView.backgroundColor = [UIColor whiteColor];
    self.bottomView.hidden = YES;
    [self.view addSubview:_bottomView];
    self.myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(75 / 2 * kAdjustParamater,50 * kAdjustParamater, 300 * kAdjustParamater, 100 * kAdjustParamater)];
    self.myPickerView.showsSelectionIndicator = YES;
    self.myPickerView.dataSource = self;
    self.myPickerView.delegate = self;
    [self.myPickerView selectRow:0 inComponent:0 animated:YES];
    [self.bottomView addSubview:_myPickerView];
    
    UIButton *finishButton = [UIButton buttonWithType:UIButtonTypeSystem];
    finishButton.backgroundColor = [UIColor redColor];
    finishButton.frame = CGRectMake(280 * kAdjustParamater, 5 * kAdjustParamater, 70 * kAdjustParamater, 30 * kAdjustParamater);
    [finishButton setTitle:@"完成" forState:UIControlStateNormal];
    [finishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    finishButton.backgroundColor = [UIColor colorWithRed:84 / 255.0 green:199 / 255.0 blue:222 / 255.0 alpha:1];
    finishButton.layer.cornerRadius = 2 * kAdjustParamater;
    [finishButton addTarget:self action:@selector(clickPickview:) forControlEvents:UIControlEventTouchUpInside];
    finishButton.titleLabel.font = [UIFont systemFontOfSize:k20Big];
    [self.bottomView addSubview:finishButton];
}

// 点击pickerview的时候完成
- (void)clickPickview:(UIButton *)button
{
    NSLog(@"self.foreverString = %@", self.foreverString);
    NSLog(@"count = %ld", self.pickviewDataArray.count);
    if (self.foreverString.length == 0) {
        // 说明是不限
        self.foreverString = @"不限";
        [self changeFindButtonShouldZiFuChuan];
    }
   
    if (self.pickviewDataArray.count == 3) {
        // 说明需要修改性别
        [self.userMessageDic setValue:self.foreverString forKey:@"gender"];
        [self changeFindButtonShouldZiFuChuan];
    } else if (self.pickviewDataArray.count == 6){
        // 说明需要修改年龄
        [self.userMessageDic setValue:self.foreverString forKey:@"age"];
        [self changeFindButtonShouldZiFuChuan];
    } else {
        // 说明需要修改基因相似度
        [self.userMessageDic setValue:self.foreverString forKey:@"xiangsidu"];
        [self changeFindButtonShouldZiFuChuan];
    }
    [self.findPeopleWithConditionTableView reloadData];
    self.bottomView.hidden = YES;
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.pickviewDataArray.count;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 30 * kAdjustParamater;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    return 100 * kAdjustParamater;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    // 取得指定列的宽度
    CGFloat width = [self pickerView:pickerView widthForComponent:component];
    // 取得指定列的高度
    CGFloat height = [self pickerView:pickerView rowHeightForComponent:component];
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    UILabel *labelOnComponent = [[UILabel alloc] init];
    labelOnComponent.frame = myView.frame;
   // labelOnComponent.tag = 210;
    labelOnComponent.text = self.pickviewDataArray[row];
    labelOnComponent.textAlignment = NSTextAlignmentCenter;
    [myView addSubview:labelOnComponent];
    return myView;
}

// 点击时回调
 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
  //  self.myPickerView.hidden = YES;
  //  NSLog(@"pickerview row = %ld", row);
    // 取得对应的行数
    NSInteger tempRow = [pickerView selectedRowInComponent:component];
    // 取得子视图
    UIView *tempView = (UIView *)[pickerView viewForRow:tempRow forComponent:0];
    UILabel *tempLabel = (UILabel *)[tempView subviews].lastObject;
    NSLog(@"tempLabel = %@", tempLabel.text);
    self.foreverString = tempLabel.text;
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
